Page({
  data: {
    oneActiveIndex: 0,
    canLook: '',
    list: [{
        text: "纳税",
        text2: "",
        imgSrc: "https://zx-1311146360.cos.ap-shanghai.myqcloud.com/trade/6.png",
      },
      {
        text: "营收",
        text2: "",
        imgSrc: "https://zx-1311146360.cos.ap-shanghai.myqcloud.com/trade/10.png",
      },

      {
        text: "用工",
        text2: "",
        imgSrc: "https://zx-1311146360.cos.ap-shanghai.myqcloud.com/trade/12.png",
      },
      {
        text: "用电",
        text2: "",
        imgSrc: "https://zx-1311146360.cos.ap-shanghai.myqcloud.com/trade/11.png",
      },
      {
        text: "专利",
        text2: "",
        imgSrc: "https://zx-1311146360.cos.ap-shanghai.myqcloud.com/trade/13.png",
      },
      {
        text: "净利润",
        text2: "",
        imgSrc: "https://zx-1311146360.cos.ap-shanghai.myqcloud.com/trade/4.png",
      },
      {
        text: "贷款余额",
        text2: "",
        imgSrc: "https://zx-1311146360.cos.ap-shanghai.myqcloud.com/trade/2.png",
      },
      {
        text: "负债率",
        text2: "",
        imgSrc: "https://zx-1311146360.cos.ap-shanghai.myqcloud.com/trade/3.png",
      },
      {
        text: "涉案",
        text2: "",
        imgSrc: "https://zx-1311146360.cos.ap-shanghai.myqcloud.com/trade/8.png",
      },
      {
        text: "不良贷款",
        text2: "",
        imgSrc: "https://zx-1311146360.cos.ap-shanghai.myqcloud.com/trade/1.png",
      },
    ],
    industCode: [],
    extraObj: {},
    listEcharts: [],
    loading: true
  },

  onReady: function () {},
  onShow: function (e) {},
  async onLoad(e) {
    const keyList = JSON.parse(e.keyList)
    const extraObj = {
      tab: 'tax'
    }
    this.setData({
      industCode: keyList,
      extraObj: extraObj
    })
    this.initInfos()
    const vipCode = await getApp().globalData.checkVipStatus()
    if (vipCode == 'ordinary' || vipCode == 'notVipBindFI' || vipCode == 'visitor') {
      this.setData({
        canLook: 'no'
      })
    } else {
      this.setData({
        canLook: 'yes'
      })
    }
  },
  // 滑动底部
  onReachBottom: function () {},
  /**
   * methods
   */
  // 初始化数据
  async initInfos() {
    const params = {
      industCode: this.data.industCode,
    }
    console.log({
      ...params,
      ...this.data.extraObj
    }, '请求参数')
    this.setData({
      loading: true
    })
    const {
      data
    } = await getApp().globalData.request(
      "/map/industryAnalysis", {
        ...params,
        ...this.data.extraObj
      },
      "POST"
    );
    console.log(data, 'data')
    if (data && data.length > 0) {
      data.forEach(pre => {
        this.data.listEcharts.push({
          xData: pre.x,
          yData1: pre.y1,
          yData2: pre.y2,
          title: pre.title,
          unit: pre.unit,
          type: "line",
        });
      })
      this.setData({
        listEcharts: this.data.listEcharts
      })
    }
    this.setData({
      loading: false
    })
  },
  async tabTuijian(e) {
    const vipCode = await getApp().globalData.checkVipStatus()
    if (vipCode === 'ordinary' || vipCode === 'notVipBindFI' || vipCode === 'visitor') {
      wx.showModal({
        title: '提示',
        content: '该功能为VIP会员功能，请联系客服了解详情。',
        showCancel: false,
        confirmText: '确定',
        success: function () {}
      })
      return
    }
    this.setData({
      listEcharts: [],
      oneActiveIndex: e.currentTarget.dataset.index
    })
    this.goSearch(e.currentTarget.dataset.itemtitle)
  },
  // 企业搜索
  tozhaoqiyeClick() {
    wx.navigateTo({
      url: "/packageA/pages/homelink/zhaoqiye/zhaoqiye",
    });
  },

  goSearch(item) {
    switch (item) {
      case "纳税":
        const params0 = {
          tab: 'tax',
        };
        this.setData({
          extraObj: params0,
        });
        this.initInfos();
        break;
      case "营收":
        const params1 = {
          tab: 'revenue',
        };
        this.setData({
          extraObj: params1,
        });
        this.initInfos();
        break;
      case "用工":
        const params2 = {
          tab: 'person',
        };
        this.setData({
          extraObj: params2,
        });
        this.initInfos();
        break;
      case "用电":
        const params3 = {
          tab: 'electric',
        };
        this.setData({
          extraObj: params3,
        });
        this.initInfos();
        break;
      case "专利":
        const params4 = {
          tab: 'patent',
        };
        this.setData({
          extraObj: params4,
        });
        this.initInfos();
        break;
      case "净利润":
        const params5 = {
          tab: 'netProfits',
        };
        this.setData({
          extraObj: params5,
        });
        this.initInfos();
        break;
      case "贷款余额":
        const params6 = {
          tab: 'loan',
        };
        this.setData({
          extraObj: params6,
        });
        this.initInfos();
        break;
      case "负债率":
        const params7 = {
          tab: 'debt',
        };
        this.setData({
          extraObj: params7,
        });
        this.initInfos();
        break;
      case "涉案":
        const params8 = {
          tab: 'case',
        };
        this.setData({
          extraObj: params8,
        });
        this.initInfos();
        break;
      case "不良贷款":
        const params9 = {
          tab: 'badLoan',
        };
        this.setData({
          extraObj: params9,
        });
        this.initInfos();
        break;
      default:
        break;
    }
  },

});